<template>
	<view>
		<view style="padding: 15px;">
			<u-grid :border="false" col="2">
				<u-grid-item @click="toStore(item.id)" v-for="(item,index) in storeList" :key="index">
					<image style="width: 100px; height: 100px; border-radius: 8px;" :src="item.image">
					</image>
					<text class="text_recommend">{{item.homeName}}</text>
					<view style="display: flex; margin: 10px 0 15px 0;">
						<u-icon class="icon_common" name="star" color="#E6A23C"></u-icon><text
							class="text_common">{{item.collectNum}}</text>
						<u-icon class="icon_common" name="chat" color="#409EFF"></u-icon><text
							class="text_common">{{item.commentNum}}</text>
					</view>
				</u-grid-item>
			</u-grid>
		</view>
		<!-- 空状态 -->
		<view v-if="isEmpty">
			<u-empty mode="favor" icon="http://cdn.uviewui.com/uview/empty/car.png">
			</u-empty>
		</view>
	</view>
</template>

<script setup>
	import {
		queryCollectStore
	} from "@/api/collectstore/index.js";
	import {
		ref
	} from "vue";
	import {
		getUserInfo
	} from "@/stores/index.js";
	import {
		onLoad
	} from "@dcloudio/uni-app";

	const user = getUserInfo();
	const storeList = ref([]);
	const isEmpty = ref(false);
	onLoad(() => {
		getCollectStore();
	})

	//获取当前用户的收藏店铺数据
	const getCollectStore = () => {
		queryCollectStore(user.id).then((res) => {
			if(res.code === 200 && res.data !== null) {
				storeList.value = res.data;
			}else{
				isEmpty.value = true;
			}
		})
	}
	
	//跳转到店铺页面
	const toStore = (storeId) => {
		uni.navigateTo({
			url: "/pages/store/store?storeId=" + storeId
		})
	}
</script>

<style scoped lang="scss">
	.icon_common {
		margin-right: 15px;
	}

	.text_common {
		color: #909399;
		font-size: 13px;
		margin-right: 15px;
	}

	.text_recommend {
		margin-top: 10px;
		padding: 0 10px 0 10px;
		font-size: 14px;
		color: #303133;
		font-weight: 600;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
		font-family: "华文楷体";
	}
</style>